local enchou = fk.CreateSkill {
  name = "rmt__enchou"
}

Fk:loadTranslationTable{
  ["rmt__enchou"] = "恩仇",
  [":rmt__enchou"] = "出牌阶段限一次，你可观看一名有装备栏被废除的其他角色的手牌并获得其中一张牌，然后你恢复其一个装备栏。",

  ["rmt__enchou_get"] = "获得",
  ["#rmt__enchou-ask"] = "恩仇：获得 %dest 一张手牌，然后恢复其一个装备栏",
  ["#rmt__enchou-choice"] = "恩仇：恢复 %dest 一个装备栏",

  ["$rmt__enchou1"] = "江湖快意，恩仇必报！",
  ["$rmt__enchou2"] = "今日之因，明日之果！"
}

local U = require "packages/utility/utility"

--- 获取被废除的装备栏
---@param player Player
local function getSealedEquipSlot(player)
  local all_slots = {"WeaponSlot", "ArmorSlot", "DefensiveRideSlot", "OffensiveRideSlot", "TreasureSlot"}
  return table.filter(all_slots, function(slot) return table.contains(player.sealedSlots, slot) end)
end

enchou:addEffect("active", {
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(enchou.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and #getSealedEquipSlot(to_select) > 0 and to_select ~= player and not to_select:isKongcheng()
  end,
  on_use = function(self, room, effect)
    ---@type string
    local skillName = enchou.name
    local player = effect.from
    local target = effect.tos[1]
    local cids = target:getCardIds("h")
    local cards, _ = U.askforChooseCardsAndChoice(player, cids, {"rmt__enchou_get"}, skillName, "#rmt__enchou-ask::" .. target.id)
    room:obtainCard(player, cards[1], false, fk.ReasonPrey, player, skillName)
    if target:isAlive() and player:isAlive() then
      local choices = getSealedEquipSlot(target)
      if #choices > 0 then
        local choice = room:askToChoice(player, {
          choices = choices,
          skill_name = skillName,
          prompt = "#rmt__enchou-choice::" .. target.id,
        })
        room:resumePlayerArea(target, {choice})
      end
    end
  end,
})

return enchou
